package cn.ibizlab.odoo.core.odoo_sale.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Isale_report;
import cn.ibizlab.odoo.core.odoo_sale.domain.Sale_report;
import cn.ibizlab.odoo.core.odoo_sale.filter.Sale_reportSearchContext;
import cn.ibizlab.odoo.core.odoo_sale.service.ISale_reportService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[销售分析报告] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Sale_reportServiceImpl implements ISale_reportService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Isale_reportClientService sale_reportClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //sale_reportClientService.removeBatch(sale_reports) ;

    }

    @Override
    public Sale_report get(Integer id) {
        Isale_report clientModel = sale_reportClientService.createModel();
        clientModel.setId(id);
        sale_reportClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Sale_report get(Sale_report sale_report) {
        Sale_report retsale_report = this.get(sale_report.getId()) ;
    	BeanCopier copier=BeanCopier.create(retsale_report.getClass(), sale_report.getClass(), false);
        copier.copy(retsale_report, sale_report, null);
        return sale_report ;
    }

    @Override
    public boolean create(Sale_report sale_report) {
        boolean bOk = false ;
        Isale_report clientModel = this.convert2Model(sale_report,null);
        sale_reportClientService.create(clientModel) ;
        this.convert2Domain(clientModel,sale_report);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean update(Sale_report sale_report) {
        boolean bOk = false ;
        Isale_report clientModel = this.convert2Model(sale_report,null);
        sale_reportClientService.update(clientModel) ;
        this.convert2Domain(clientModel,sale_report) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Isale_report clientModel = sale_reportClientService.createModel();
        clientModel.setId(id);
        sale_reportClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Sale_report> sale_reports, int batchSize) {

                        //sale_reportClientService.createBatch(sale_reports,batchSize) ;

    }

    @Override
    public void updateBatch(List<Sale_report> sale_reports, int batchSize) {

        //sale_reportClientService.updateBatch(sale_reports,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Sale_report> searchDefault(Sale_reportSearchContext context) {
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据分析账户查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_analytic_account(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据销售渠道查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_team(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据产品种类查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_categ(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据价格表查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_pricelist(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据产品查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_product(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据产品模板查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_product_tmpl(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据公司查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_company(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据国家/地区查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_country(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_commercial_partner(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_partner(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_user(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据销售订单查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_order(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据仓库查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_warehouse(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据产品计量单位查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_product_uom(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据UTM 营销活动查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_campaign(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据UTM媒体查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_medium(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据UTM来源查询
     */
    @Override
    public Page<Sale_report> selectByOdoo_source(Integer id){
        Sale_reportSearchContext context = new Sale_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_report> list = new ArrayList<Sale_report>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_report> clientModelList = sale_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Isale_report convert2Model(Sale_report domain , Isale_report model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = sale_reportClientService.createModel() ;
        }

         if(domain.getPrice_subtotalDirtyFlag())
            model.setPrice_subtotal(domain.getPrice_subtotal());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getDiscountDirtyFlag())
            model.setDiscount(domain.getDiscount());
         if(domain.getDiscount_amountDirtyFlag())
            model.setDiscount_amount(domain.getDiscount_amount());
         if(domain.getVolumeDirtyFlag())
            model.setVolume(domain.getVolume());
         if(domain.getPrice_totalDirtyFlag())
            model.setPrice_total(domain.getPrice_total());
         if(domain.getConfirmation_dateDirtyFlag())
            model.setConfirmation_date(domain.getConfirmation_date());
         if(domain.getDateDirtyFlag())
            model.setDate(domain.getDate());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getQty_to_invoiceDirtyFlag())
            model.setQty_to_invoice(domain.getQty_to_invoice());
         if(domain.getNbrDirtyFlag())
            model.setNbr(domain.getNbr());
         if(domain.getWeightDirtyFlag())
            model.setWeight(domain.getWeight());
         if(domain.getProduct_uom_qtyDirtyFlag())
            model.setProduct_uom_qty(domain.getProduct_uom_qty());
         if(domain.getUntaxed_amount_to_invoiceDirtyFlag())
            model.setUntaxed_amount_to_invoice(domain.getUntaxed_amount_to_invoice());
         if(domain.getUntaxed_amount_invoicedDirtyFlag())
            model.setUntaxed_amount_invoiced(domain.getUntaxed_amount_invoiced());
         if(domain.getWebsite_idDirtyFlag())
            model.setWebsite_id(domain.getWebsite_id());
         if(domain.getQty_deliveredDirtyFlag())
            model.setQty_delivered(domain.getQty_delivered());
         if(domain.getQty_invoicedDirtyFlag())
            model.setQty_invoiced(domain.getQty_invoiced());
         if(domain.getProduct_tmpl_id_textDirtyFlag())
            model.setProduct_tmpl_id_text(domain.getProduct_tmpl_id_text());
         if(domain.getWarehouse_id_textDirtyFlag())
            model.setWarehouse_id_text(domain.getWarehouse_id_text());
         if(domain.getAnalytic_account_id_textDirtyFlag())
            model.setAnalytic_account_id_text(domain.getAnalytic_account_id_text());
         if(domain.getProduct_id_textDirtyFlag())
            model.setProduct_id_text(domain.getProduct_id_text());
         if(domain.getCountry_id_textDirtyFlag())
            model.setCountry_id_text(domain.getCountry_id_text());
         if(domain.getCateg_id_textDirtyFlag())
            model.setCateg_id_text(domain.getCateg_id_text());
         if(domain.getSource_id_textDirtyFlag())
            model.setSource_id_text(domain.getSource_id_text());
         if(domain.getCampaign_id_textDirtyFlag())
            model.setCampaign_id_text(domain.getCampaign_id_text());
         if(domain.getOrder_id_textDirtyFlag())
            model.setOrder_id_text(domain.getOrder_id_text());
         if(domain.getUser_id_textDirtyFlag())
            model.setUser_id_text(domain.getUser_id_text());
         if(domain.getCommercial_partner_id_textDirtyFlag())
            model.setCommercial_partner_id_text(domain.getCommercial_partner_id_text());
         if(domain.getMedium_id_textDirtyFlag())
            model.setMedium_id_text(domain.getMedium_id_text());
         if(domain.getProduct_uom_textDirtyFlag())
            model.setProduct_uom_text(domain.getProduct_uom_text());
         if(domain.getCompany_id_textDirtyFlag())
            model.setCompany_id_text(domain.getCompany_id_text());
         if(domain.getTeam_id_textDirtyFlag())
            model.setTeam_id_text(domain.getTeam_id_text());
         if(domain.getPricelist_id_textDirtyFlag())
            model.setPricelist_id_text(domain.getPricelist_id_text());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getTeam_idDirtyFlag())
            model.setTeam_id(domain.getTeam_id());
         if(domain.getCommercial_partner_idDirtyFlag())
            model.setCommercial_partner_id(domain.getCommercial_partner_id());
         if(domain.getUser_idDirtyFlag())
            model.setUser_id(domain.getUser_id());
         if(domain.getProduct_tmpl_idDirtyFlag())
            model.setProduct_tmpl_id(domain.getProduct_tmpl_id());
         if(domain.getAnalytic_account_idDirtyFlag())
            model.setAnalytic_account_id(domain.getAnalytic_account_id());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getMedium_idDirtyFlag())
            model.setMedium_id(domain.getMedium_id());
         if(domain.getOrder_idDirtyFlag())
            model.setOrder_id(domain.getOrder_id());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getSource_idDirtyFlag())
            model.setSource_id(domain.getSource_id());
         if(domain.getCampaign_idDirtyFlag())
            model.setCampaign_id(domain.getCampaign_id());
         if(domain.getCateg_idDirtyFlag())
            model.setCateg_id(domain.getCateg_id());
         if(domain.getWarehouse_idDirtyFlag())
            model.setWarehouse_id(domain.getWarehouse_id());
         if(domain.getProduct_idDirtyFlag())
            model.setProduct_id(domain.getProduct_id());
         if(domain.getPricelist_idDirtyFlag())
            model.setPricelist_id(domain.getPricelist_id());
         if(domain.getProduct_uomDirtyFlag())
            model.setProduct_uom(domain.getProduct_uom());
         if(domain.getCountry_idDirtyFlag())
            model.setCountry_id(domain.getCountry_id());
        return model ;
    }

    public Sale_report convert2Domain( Isale_report model ,Sale_report domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Sale_report();
        }

        if(model.getPrice_subtotalDirtyFlag())
            domain.setPrice_subtotal(model.getPrice_subtotal());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getDiscountDirtyFlag())
            domain.setDiscount(model.getDiscount());
        if(model.getDiscount_amountDirtyFlag())
            domain.setDiscount_amount(model.getDiscount_amount());
        if(model.getVolumeDirtyFlag())
            domain.setVolume(model.getVolume());
        if(model.getPrice_totalDirtyFlag())
            domain.setPrice_total(model.getPrice_total());
        if(model.getConfirmation_dateDirtyFlag())
            domain.setConfirmation_date(model.getConfirmation_date());
        if(model.getDateDirtyFlag())
            domain.setDate(model.getDate());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getQty_to_invoiceDirtyFlag())
            domain.setQty_to_invoice(model.getQty_to_invoice());
        if(model.getNbrDirtyFlag())
            domain.setNbr(model.getNbr());
        if(model.getWeightDirtyFlag())
            domain.setWeight(model.getWeight());
        if(model.getProduct_uom_qtyDirtyFlag())
            domain.setProduct_uom_qty(model.getProduct_uom_qty());
        if(model.getUntaxed_amount_to_invoiceDirtyFlag())
            domain.setUntaxed_amount_to_invoice(model.getUntaxed_amount_to_invoice());
        if(model.getUntaxed_amount_invoicedDirtyFlag())
            domain.setUntaxed_amount_invoiced(model.getUntaxed_amount_invoiced());
        if(model.getWebsite_idDirtyFlag())
            domain.setWebsite_id(model.getWebsite_id());
        if(model.getQty_deliveredDirtyFlag())
            domain.setQty_delivered(model.getQty_delivered());
        if(model.getQty_invoicedDirtyFlag())
            domain.setQty_invoiced(model.getQty_invoiced());
        if(model.getProduct_tmpl_id_textDirtyFlag())
            domain.setProduct_tmpl_id_text(model.getProduct_tmpl_id_text());
        if(model.getWarehouse_id_textDirtyFlag())
            domain.setWarehouse_id_text(model.getWarehouse_id_text());
        if(model.getAnalytic_account_id_textDirtyFlag())
            domain.setAnalytic_account_id_text(model.getAnalytic_account_id_text());
        if(model.getProduct_id_textDirtyFlag())
            domain.setProduct_id_text(model.getProduct_id_text());
        if(model.getCountry_id_textDirtyFlag())
            domain.setCountry_id_text(model.getCountry_id_text());
        if(model.getCateg_id_textDirtyFlag())
            domain.setCateg_id_text(model.getCateg_id_text());
        if(model.getSource_id_textDirtyFlag())
            domain.setSource_id_text(model.getSource_id_text());
        if(model.getCampaign_id_textDirtyFlag())
            domain.setCampaign_id_text(model.getCampaign_id_text());
        if(model.getOrder_id_textDirtyFlag())
            domain.setOrder_id_text(model.getOrder_id_text());
        if(model.getUser_id_textDirtyFlag())
            domain.setUser_id_text(model.getUser_id_text());
        if(model.getCommercial_partner_id_textDirtyFlag())
            domain.setCommercial_partner_id_text(model.getCommercial_partner_id_text());
        if(model.getMedium_id_textDirtyFlag())
            domain.setMedium_id_text(model.getMedium_id_text());
        if(model.getProduct_uom_textDirtyFlag())
            domain.setProduct_uom_text(model.getProduct_uom_text());
        if(model.getCompany_id_textDirtyFlag())
            domain.setCompany_id_text(model.getCompany_id_text());
        if(model.getTeam_id_textDirtyFlag())
            domain.setTeam_id_text(model.getTeam_id_text());
        if(model.getPricelist_id_textDirtyFlag())
            domain.setPricelist_id_text(model.getPricelist_id_text());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getTeam_idDirtyFlag())
            domain.setTeam_id(model.getTeam_id());
        if(model.getCommercial_partner_idDirtyFlag())
            domain.setCommercial_partner_id(model.getCommercial_partner_id());
        if(model.getUser_idDirtyFlag())
            domain.setUser_id(model.getUser_id());
        if(model.getProduct_tmpl_idDirtyFlag())
            domain.setProduct_tmpl_id(model.getProduct_tmpl_id());
        if(model.getAnalytic_account_idDirtyFlag())
            domain.setAnalytic_account_id(model.getAnalytic_account_id());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getMedium_idDirtyFlag())
            domain.setMedium_id(model.getMedium_id());
        if(model.getOrder_idDirtyFlag())
            domain.setOrder_id(model.getOrder_id());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getSource_idDirtyFlag())
            domain.setSource_id(model.getSource_id());
        if(model.getCampaign_idDirtyFlag())
            domain.setCampaign_id(model.getCampaign_id());
        if(model.getCateg_idDirtyFlag())
            domain.setCateg_id(model.getCateg_id());
        if(model.getWarehouse_idDirtyFlag())
            domain.setWarehouse_id(model.getWarehouse_id());
        if(model.getProduct_idDirtyFlag())
            domain.setProduct_id(model.getProduct_id());
        if(model.getPricelist_idDirtyFlag())
            domain.setPricelist_id(model.getPricelist_id());
        if(model.getProduct_uomDirtyFlag())
            domain.setProduct_uom(model.getProduct_uom());
        if(model.getCountry_idDirtyFlag())
            domain.setCountry_id(model.getCountry_id());
        return domain ;
    }


}
